package templates

import java.awt.Color
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.TextBox
import org.uqbar.lacar.ui.model.Action
import org.uqbar.arena.widgets.Selector

class AgregarNuevo {
	
	/** Crea un label y un textBox */
	def labelAndBox(Panel p, String caption, String property) {
		new Label(p).setText(caption)
		new TextBox(p).bindValueToProperty(property)
	}
	
	/** Crea un label y un selector con sus respectivos bindings */
	def labelAndSelector(Panel p, String caption,String listProperty ,String property) {
		new Label(p).setText(caption)

		new Selector(p) => [
			allowNull(false)
			bindItemsToProperty(listProperty)
			bindValueToProperty(property)
			setWidth(100)
		]
		
	}
	
	/** Crea un label, un boton, un label y una lista con sus respectivos atributos */
	def caracteristicaBundle (Panel p,String text,String property, Action action) {
		val panel = new Panel(p)
						.setLayout(new VerticalLayout)
				
			panel.setLayout(new ColumnLayout(2))
			new Label(panel).setText(text + ":").setWidth(140)
			new Button(panel) => [
				setCaption("Editar  "  + text )
				setBackground(Color ::LIGHT_GRAY)
				setWidth(160)
				onClick(action)
			]			
	
		val panel2 = new Panel(p)
			.setLayout(new VerticalLayout)
		
		
		new Label(panel2) => [
			setText(text)
			setBackground(Color :: LIGHT_GRAY)
			setWidth(280)
			]
			
		new List(panel2) => [
				bindItemsToProperty(property)
				setWidth(280)
				setHeight(35)
			]		
			
	}
	
}